<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.9.1"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>AIfES 2: aialgo_sequential_training.h File Reference</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    extensions: ["tex2jax.js"],
    jax: ["input/TeX","output/HTML-CSS"],
});
</script>
<script type="text/javascript" async="async" src="https://cdn.jsdelivr.net/npm/mathjax@2/MathJax.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="AIfES_logo_small.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">AIfES 2
   &#160;<span id="projectnumber">2.0.0</span>
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.1 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search','.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('aialgo__sequential__training_8h.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="summary">
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">aialgo_sequential_training.h File Reference</div>  </div>
</div><!--header-->
<div class="contents">

<p>Functions required for the training of models.  
<a href="#details">More...</a></p>

<p><a href="aialgo__sequential__training_8h_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:aaa72bf9da57a600c0d4fef4ba03f725e"><td class="memItemLeft" align="right" valign="top">uint32_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="aialgo__sequential__training_8h.html#aaa72bf9da57a600c0d4fef4ba03f725e">aialgo_sizeof_training_memory</a> (<a class="el" href="structaimodel.html">aimodel_t</a> *model, <a class="el" href="structaiopti.html">aiopti_t</a> *optimizer)</td></tr>
<tr class="memdesc:aaa72bf9da57a600c0d4fef4ba03f725e"><td class="mdescLeft">&#160;</td><td class="mdescRight">Calculate the memory requirements for model training.  <a href="aialgo__sequential__training_8h.html#aaa72bf9da57a600c0d4fef4ba03f725e">More...</a><br /></td></tr>
<tr class="separator:aaa72bf9da57a600c0d4fef4ba03f725e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aa6ae098c2add3651d216724f102e931b"><td class="memItemLeft" align="right" valign="top">uint8_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="aialgo__sequential__training_8h.html#aa6ae098c2add3651d216724f102e931b">aialgo_schedule_training_memory</a> (<a class="el" href="structaimodel.html">aimodel_t</a> *model, <a class="el" href="structaiopti.html">aiopti_t</a> *optimizer, void *memory_ptr, uint32_t memory_size)</td></tr>
<tr class="memdesc:aa6ae098c2add3651d216724f102e931b"><td class="mdescLeft">&#160;</td><td class="mdescRight">Assign the memory for model training.  <a href="aialgo__sequential__training_8h.html#aa6ae098c2add3651d216724f102e931b">More...</a><br /></td></tr>
<tr class="separator:aa6ae098c2add3651d216724f102e931b"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a62a55277765b0bdd5c88955eb92e4c13"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="aialgo__sequential__training_8h.html#a62a55277765b0bdd5c88955eb92e4c13">aialgo_init_model_for_training</a> (<a class="el" href="structaimodel.html">aimodel_t</a> *model, <a class="el" href="structaiopti.html">aiopti_t</a> *optimizer)</td></tr>
<tr class="memdesc:a62a55277765b0bdd5c88955eb92e4c13"><td class="mdescLeft">&#160;</td><td class="mdescRight">Initialize the optimization memory of the model layers.  <a href="aialgo__sequential__training_8h.html#a62a55277765b0bdd5c88955eb92e4c13">More...</a><br /></td></tr>
<tr class="separator:a62a55277765b0bdd5c88955eb92e4c13"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aca4ec290b2db30cc76ad78aff649a69d"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="aialgo__sequential__training_8h.html#aca4ec290b2db30cc76ad78aff649a69d">aialgo_backward_model</a> (<a class="el" href="structaimodel.html">aimodel_t</a> *model, <a class="el" href="structaitensor.html">aitensor_t</a> *target_data)</td></tr>
<tr class="memdesc:aca4ec290b2db30cc76ad78aff649a69d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Perform the backward pass.  <a href="aialgo__sequential__training_8h.html#aca4ec290b2db30cc76ad78aff649a69d">More...</a><br /></td></tr>
<tr class="separator:aca4ec290b2db30cc76ad78aff649a69d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a6557fccf302f653bcdcb77830463d14d"><td class="memItemLeft" align="right" valign="top">uint8_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="aialgo__sequential__training_8h.html#a6557fccf302f653bcdcb77830463d14d">aialgo_train_model</a> (<a class="el" href="structaimodel.html">aimodel_t</a> *model, <a class="el" href="structaitensor.html">aitensor_t</a> *input_tensor, <a class="el" href="structaitensor.html">aitensor_t</a> *target_tensor, <a class="el" href="structaiopti.html">aiopti_t</a> *optimizer, uint32_t batch_size)</td></tr>
<tr class="memdesc:a6557fccf302f653bcdcb77830463d14d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Perform one training epoch on all data batches of the dataset using backpropagation.  <a href="aialgo__sequential__training_8h.html#a6557fccf302f653bcdcb77830463d14d">More...</a><br /></td></tr>
<tr class="separator:a6557fccf302f653bcdcb77830463d14d"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ab06a58b69f3136374e2dc6664f56e0c7"><td class="memItemLeft" align="right" valign="top">uint8_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="aialgo__sequential__training_8h.html#ab06a58b69f3136374e2dc6664f56e0c7">aialgo_calc_loss_model_f32</a> (<a class="el" href="structaimodel.html">aimodel_t</a> *model, <a class="el" href="structaitensor.html">aitensor_t</a> *input_data, <a class="el" href="structaitensor.html">aitensor_t</a> *target_data, float *result)</td></tr>
<tr class="memdesc:ab06a58b69f3136374e2dc6664f56e0c7"><td class="mdescLeft">&#160;</td><td class="mdescRight">Calculate the loss in <a class="el" href="aimath__f32_8h.html">F32 </a> data type.  <a href="aialgo__sequential__training_8h.html#ab06a58b69f3136374e2dc6664f56e0c7">More...</a><br /></td></tr>
<tr class="separator:ab06a58b69f3136374e2dc6664f56e0c7"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a9d2a18685d1db30e00c91c194bea8104"><td class="memItemLeft" align="right" valign="top">uint8_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="aialgo__sequential__training_8h.html#a9d2a18685d1db30e00c91c194bea8104">aialgo_calc_loss_model_q31</a> (<a class="el" href="structaimodel.html">aimodel_t</a> *model, <a class="el" href="structaitensor.html">aitensor_t</a> *input_data, <a class="el" href="structaitensor.html">aitensor_t</a> *target_data, <a class="el" href="structaiscalar__q31.html">aiscalar_q31_t</a> *result)</td></tr>
<tr class="memdesc:a9d2a18685d1db30e00c91c194bea8104"><td class="mdescLeft">&#160;</td><td class="mdescRight">Calculate the loss in <a class="el" href="aimath__q31_8h.html">Q31 </a> data type.  <a href="aialgo__sequential__training_8h.html#a9d2a18685d1db30e00c91c194bea8104">More...</a><br /></td></tr>
<tr class="separator:a9d2a18685d1db30e00c91c194bea8104"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a20ba9e0bdcfd4e36bc1168789de7e99f"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="aialgo__sequential__training_8h.html#a20ba9e0bdcfd4e36bc1168789de7e99f">aialgo_zero_gradients_model</a> (<a class="el" href="structaimodel.html">aimodel_t</a> *model, <a class="el" href="structaiopti.html">aiopti_t</a> *optimizer)</td></tr>
<tr class="memdesc:a20ba9e0bdcfd4e36bc1168789de7e99f"><td class="mdescLeft">&#160;</td><td class="mdescRight">Set the gradients to zero.  <a href="aialgo__sequential__training_8h.html#a20ba9e0bdcfd4e36bc1168789de7e99f">More...</a><br /></td></tr>
<tr class="separator:a20ba9e0bdcfd4e36bc1168789de7e99f"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a4650ca244c2d5086eb80190d2416f86e"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="aialgo__sequential__training_8h.html#a4650ca244c2d5086eb80190d2416f86e">aialgo_update_params_model</a> (<a class="el" href="structaimodel.html">aimodel_t</a> *model, <a class="el" href="structaiopti.html">aiopti_t</a> *optimizer)</td></tr>
<tr class="memdesc:a4650ca244c2d5086eb80190d2416f86e"><td class="mdescLeft">&#160;</td><td class="mdescRight">Perform the optimization step on the model parameters.  <a href="aialgo__sequential__training_8h.html#a4650ca244c2d5086eb80190d2416f86e">More...</a><br /></td></tr>
<tr class="separator:a4650ca244c2d5086eb80190d2416f86e"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ab19a3d00e7ac130806780cc90e317a09"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="aialgo__sequential__training_8h.html#ab19a3d00e7ac130806780cc90e317a09">aialgo_print_loss_specs</a> (<a class="el" href="structailoss.html">ailoss_t</a> *loss)</td></tr>
<tr class="memdesc:ab19a3d00e7ac130806780cc90e317a09"><td class="mdescLeft">&#160;</td><td class="mdescRight">Print the loss specs.  <a href="aialgo__sequential__training_8h.html#ab19a3d00e7ac130806780cc90e317a09">More...</a><br /></td></tr>
<tr class="separator:ab19a3d00e7ac130806780cc90e317a09"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:aa0a7ab4189d2f68c675d42aa687758e6"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="aialgo__sequential__training_8h.html#aa0a7ab4189d2f68c675d42aa687758e6">aialgo_print_optimizer_specs</a> (<a class="el" href="structaiopti.html">aiopti_t</a> *opti)</td></tr>
<tr class="memdesc:aa0a7ab4189d2f68c675d42aa687758e6"><td class="mdescLeft">&#160;</td><td class="mdescRight">Print the optimizer specs.  <a href="aialgo__sequential__training_8h.html#aa0a7ab4189d2f68c675d42aa687758e6">More...</a><br /></td></tr>
<tr class="separator:aa0a7ab4189d2f68c675d42aa687758e6"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ab6ea378b18812cf68fb4ae70c57380a5"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="aialgo__sequential__training_8h.html#ab6ea378b18812cf68fb4ae70c57380a5">aialgo_initialize_parameters_model</a> (<a class="el" href="structaimodel.html">aimodel_t</a> *model)</td></tr>
<tr class="memdesc:ab6ea378b18812cf68fb4ae70c57380a5"><td class="mdescLeft">&#160;</td><td class="mdescRight">Initialize the parameters of the given model with their default initialization method.  <a href="aialgo__sequential__training_8h.html#ab6ea378b18812cf68fb4ae70c57380a5">More...</a><br /></td></tr>
<tr class="separator:ab6ea378b18812cf68fb4ae70c57380a5"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Functions required for the training of models. </p>
<dl class="section version"><dt>Version</dt><dd>2.2.0 </dd></dl>
<dl class="section copyright"><dt>Copyright</dt><dd>Copyright (C) 2020-2023 Fraunhofer Institute for Microelectronic Circuits and Systems. All rights reserved.<br  />
<br  />
 AIfES is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.<br  />
<br  />
 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.<br  />
<br  />
 You should have received a copy of the GNU Affero General Public License along with this program. If not, see <a href="https://www.gnu.org/licenses/">https://www.gnu.org/licenses/</a>.</dd></dl>
<p>The functions target memory allocation/scheduling and the backpropagation for model training </p>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="aca4ec290b2db30cc76ad78aff649a69d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aca4ec290b2db30cc76ad78aff649a69d">&#9670;&nbsp;</a></span>aialgo_backward_model()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void aialgo_backward_model </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structaimodel.html">aimodel_t</a> *&#160;</td>
          <td class="paramname"><em>model</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>target_data</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Perform the backward pass. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">*model</td><td>The model </td></tr>
    <tr><td class="paramname">*target_data</td><td>The tensor containing the target data / labels </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="ab06a58b69f3136374e2dc6664f56e0c7"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ab06a58b69f3136374e2dc6664f56e0c7">&#9670;&nbsp;</a></span>aialgo_calc_loss_model_f32()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">uint8_t aialgo_calc_loss_model_f32 </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structaimodel.html">aimodel_t</a> *&#160;</td>
          <td class="paramname"><em>model</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>input_data</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>target_data</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">float *&#160;</td>
          <td class="paramname"><em>result</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Calculate the loss in <a class="el" href="aimath__f32_8h.html">F32 </a> data type. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">*model</td><td>The model </td></tr>
    <tr><td class="paramname">*input_data</td><td>Tensor containing the input data </td></tr>
    <tr><td class="paramname">*target_data</td><td>Tensor containing the target data / labels </td></tr>
    <tr><td class="paramname">*result</td><td>The calculated loss will be written here </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a9d2a18685d1db30e00c91c194bea8104"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a9d2a18685d1db30e00c91c194bea8104">&#9670;&nbsp;</a></span>aialgo_calc_loss_model_q31()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">uint8_t aialgo_calc_loss_model_q31 </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structaimodel.html">aimodel_t</a> *&#160;</td>
          <td class="paramname"><em>model</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>input_data</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>target_data</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structaiscalar__q31.html">aiscalar_q31_t</a> *&#160;</td>
          <td class="paramname"><em>result</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Calculate the loss in <a class="el" href="aimath__q31_8h.html">Q31 </a> data type. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">*model</td><td>The model </td></tr>
    <tr><td class="paramname">*input_data</td><td>Tensor containing the input data </td></tr>
    <tr><td class="paramname">*target_data</td><td>Tensor containing the target data / labels </td></tr>
    <tr><td class="paramname">*result</td><td>The calculated loss will be written here. The zero_point and the scale should be set to proper values. </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a62a55277765b0bdd5c88955eb92e4c13"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a62a55277765b0bdd5c88955eb92e4c13">&#9670;&nbsp;</a></span>aialgo_init_model_for_training()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void aialgo_init_model_for_training </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structaimodel.html">aimodel_t</a> *&#160;</td>
          <td class="paramname"><em>model</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structaiopti.html">aiopti_t</a> *&#160;</td>
          <td class="paramname"><em>optimizer</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Initialize the optimization memory of the model layers. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">*model</td><td>The model </td></tr>
    <tr><td class="paramname">*optimizer</td><td>The optimizer that is used for training </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="ab6ea378b18812cf68fb4ae70c57380a5"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ab6ea378b18812cf68fb4ae70c57380a5">&#9670;&nbsp;</a></span>aialgo_initialize_parameters_model()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void aialgo_initialize_parameters_model </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structaimodel.html">aimodel_t</a> *&#160;</td>
          <td class="paramname"><em>model</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Initialize the parameters of the given model with their default initialization method. </p>
<p>Initialize the parameters of all layers that have a default initialization function (<a class="el" href="structailayer.html#aedac95cb35a037d0e513ac690c34681a" title="Initialize the (trainable and not trainable) parameters of the layer with default initializers.">ailayer.init_params</a>) configured and that are set to trainable (<a class="el" href="structailayer.html#ac0da37622121ce424bfefdeaaf924508" title="General layer settings like freezing weights or switching between training and evaluation mode.">ailayer.settings</a>[AILAYER_SETTINGS_TRAINABLE] = TRUE).</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">*model</td><td>The model to initialize </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="ab19a3d00e7ac130806780cc90e317a09"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ab19a3d00e7ac130806780cc90e317a09">&#9670;&nbsp;</a></span>aialgo_print_loss_specs()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void aialgo_print_loss_specs </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structailoss.html">ailoss_t</a> *&#160;</td>
          <td class="paramname"><em>loss</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Print the loss specs. </p>
<p>Prints information like type, data type and constants to the console.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">*loss</td><td>The loss </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="aa0a7ab4189d2f68c675d42aa687758e6"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aa0a7ab4189d2f68c675d42aa687758e6">&#9670;&nbsp;</a></span>aialgo_print_optimizer_specs()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void aialgo_print_optimizer_specs </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structaiopti.html">aiopti_t</a> *&#160;</td>
          <td class="paramname"><em>opti</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Print the optimizer specs. </p>
<p>Prints information like type, data type and constants to the console.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">*opti</td><td>The optimizer </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="aa6ae098c2add3651d216724f102e931b"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aa6ae098c2add3651d216724f102e931b">&#9670;&nbsp;</a></span>aialgo_schedule_training_memory()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">uint8_t aialgo_schedule_training_memory </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structaimodel.html">aimodel_t</a> *&#160;</td>
          <td class="paramname"><em>model</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structaiopti.html">aiopti_t</a> *&#160;</td>
          <td class="paramname"><em>optimizer</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">void *&#160;</td>
          <td class="paramname"><em>memory_ptr</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>memory_size</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Assign the memory for model training. </p>
<p>This memory is used for intermediate results, gradients and momentums.</p>
<p>The required memory size can be calculated with <a class="el" href="aialgo__sequential__training_8h.html#aaa72bf9da57a600c0d4fef4ba03f725e" title="Calculate the memory requirements for model training.">aialgo_sizeof_training_memory()</a>.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">*model</td><td>The model </td></tr>
    <tr><td class="paramname">*optimizer</td><td>The optimizer that is used for training </td></tr>
    <tr><td class="paramname">*memory_ptr</td><td>Pointer to the memory block </td></tr>
    <tr><td class="paramname">memory_size</td><td>Size of the memory block (for error checking) </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>0 if successful </dd></dl>

</div>
</div>
<a id="aaa72bf9da57a600c0d4fef4ba03f725e"></a>
<h2 class="memtitle"><span class="permalink"><a href="#aaa72bf9da57a600c0d4fef4ba03f725e">&#9670;&nbsp;</a></span>aialgo_sizeof_training_memory()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">uint32_t aialgo_sizeof_training_memory </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structaimodel.html">aimodel_t</a> *&#160;</td>
          <td class="paramname"><em>model</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structaiopti.html">aiopti_t</a> *&#160;</td>
          <td class="paramname"><em>optimizer</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Calculate the memory requirements for model training. </p>
<p>This memory is used for intermediate results, gradients and momentums.</p>
<p>Use <a class="el" href="aialgo__sequential__training_8h.html#aa6ae098c2add3651d216724f102e931b" title="Assign the memory for model training.">aialgo_schedule_training_memory()</a> to set the memory to the model.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">*model</td><td>The model </td></tr>
    <tr><td class="paramname">*optimizer</td><td>The optimizer that is used for training </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>Required memory size in bytes </dd></dl>

</div>
</div>
<a id="a6557fccf302f653bcdcb77830463d14d"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a6557fccf302f653bcdcb77830463d14d">&#9670;&nbsp;</a></span>aialgo_train_model()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">uint8_t aialgo_train_model </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structaimodel.html">aimodel_t</a> *&#160;</td>
          <td class="paramname"><em>model</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>input_tensor</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structaitensor.html">aitensor_t</a> *&#160;</td>
          <td class="paramname"><em>target_tensor</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structaiopti.html">aiopti_t</a> *&#160;</td>
          <td class="paramname"><em>optimizer</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">uint32_t&#160;</td>
          <td class="paramname"><em>batch_size</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Perform one training epoch on all data batches of the dataset using backpropagation. </p>
<p>Make shure to initialize the model (<a class="el" href="aialgo__sequential__inference_8h.html#a3fb665166082f1e7a89e23218a105ce8" title="Initialize the model structure.">aialgo_compile_model()</a>) and schedule the training memory (for example with <a class="el" href="aialgo__sequential__training_8h.html#aa6ae098c2add3651d216724f102e931b" title="Assign the memory for model training.">aialgo_schedule_training_memory()</a>) and initialize the training memory (<a class="el" href="aialgo__sequential__training_8h.html#a62a55277765b0bdd5c88955eb92e4c13" title="Initialize the optimization memory of the model layers.">aialgo_init_model_for_training()</a>) before calling this function.</p>
<p>Example: Training of an F32 model for multiple epochs </p><div class="fragment"><div class="line"><span class="keywordtype">int</span> epochs = 100;</div>
<div class="line"><span class="keywordtype">int</span> batch_size = 4;</div>
<div class="line"><span class="keywordtype">int</span> print_interval = 10;</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">float</span> loss;</div>
<div class="line"><span class="keywordflow">for</span>(i = 0; i &lt; epochs; i++)</div>
<div class="line">{</div>
<div class="line">    <span class="comment">// One epoch of training. Iterates through the whole data once</span></div>
<div class="line">    <a class="code" href="aialgo__sequential__training_8h.html#a6557fccf302f653bcdcb77830463d14d">aialgo_train_model</a>(&amp;model, &amp;input_tensor, &amp;target_tensor, optimizer, batch_size);</div>
<div class="line"> </div>
<div class="line">    <span class="comment">// Calculate and print loss every print_interval epochs</span></div>
<div class="line">    <span class="keywordflow">if</span>(i % print_interval == 0)</div>
<div class="line">    {</div>
<div class="line">        <a class="code" href="aialgo__sequential__training_8h.html#ab06a58b69f3136374e2dc6664f56e0c7">aialgo_calc_loss_model_f32</a>(&amp;model, &amp;input_tensor, &amp;target_tensor, &amp;loss);</div>
<div class="line">        printf(<span class="stringliteral">&quot;Epoch %5d: loss: %f\n&quot;</span>, i, loss);</div>
<div class="line">    }</div>
<div class="line">}</div>
<div class="ttc" id="aaialgo__sequential__training_8h_html_a6557fccf302f653bcdcb77830463d14d"><div class="ttname"><a href="aialgo__sequential__training_8h.html#a6557fccf302f653bcdcb77830463d14d">aialgo_train_model</a></div><div class="ttdeci">uint8_t aialgo_train_model(aimodel_t *model, aitensor_t *input_tensor, aitensor_t *target_tensor, aiopti_t *optimizer, uint32_t batch_size)</div><div class="ttdoc">Perform one training epoch on all data batches of the dataset using backpropagation.</div></div>
<div class="ttc" id="aaialgo__sequential__training_8h_html_ab06a58b69f3136374e2dc6664f56e0c7"><div class="ttname"><a href="aialgo__sequential__training_8h.html#ab06a58b69f3136374e2dc6664f56e0c7">aialgo_calc_loss_model_f32</a></div><div class="ttdeci">uint8_t aialgo_calc_loss_model_f32(aimodel_t *model, aitensor_t *input_data, aitensor_t *target_data, float *result)</div><div class="ttdoc">Calculate the loss in F32  data type.</div></div>
</div><!-- fragment --><dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">*model</td><td>The model </td></tr>
    <tr><td class="paramname">*input_tensor</td><td>The tensor containing the input data </td></tr>
    <tr><td class="paramname">*target_tensor</td><td>The tensor containing the target data / labels </td></tr>
    <tr><td class="paramname">*optimizer</td><td>The optimizer that is used for training </td></tr>
    <tr><td class="paramname">batch_size</td><td>Size of a batch / Number of input vektors </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a4650ca244c2d5086eb80190d2416f86e"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a4650ca244c2d5086eb80190d2416f86e">&#9670;&nbsp;</a></span>aialgo_update_params_model()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void aialgo_update_params_model </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structaimodel.html">aimodel_t</a> *&#160;</td>
          <td class="paramname"><em>model</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structaiopti.html">aiopti_t</a> *&#160;</td>
          <td class="paramname"><em>optimizer</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Perform the optimization step on the model parameters. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">*model</td><td>The model </td></tr>
    <tr><td class="paramname">*optimizer</td><td>The optimizer that is used for training </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a id="a20ba9e0bdcfd4e36bc1168789de7e99f"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a20ba9e0bdcfd4e36bc1168789de7e99f">&#9670;&nbsp;</a></span>aialgo_zero_gradients_model()</h2>

<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void aialgo_zero_gradients_model </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structaimodel.html">aimodel_t</a> *&#160;</td>
          <td class="paramname"><em>model</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype"><a class="el" href="structaiopti.html">aiopti_t</a> *&#160;</td>
          <td class="paramname"><em>optimizer</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div><div class="memdoc">

<p>Set the gradients to zero. </p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">*model</td><td>The model </td></tr>
    <tr><td class="paramname">*optimizer</td><td>The optimizer that is used for training </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
</div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="navelem"><a class="el" href="dir_d44c64559bbebec7f509842c48db8b23.html">include</a></li><li class="navelem"><a class="el" href="dir_1e5d3661ed79af157d57e64a38265d09.html">basic</a></li><li class="navelem"><a class="el" href="dir_90008ee2b0f86999412b56217da88d54.html">base</a></li><li class="navelem"><a class="el" href="dir_bd8ee926357880309e83f96383a42e12.html">aialgo</a></li><li class="navelem"><a class="el" href="aialgo__sequential__training_8h.html">aialgo_sequential_training.h</a></li>
    <li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.1 </li>
  </ul>
</div>
</body>
</html>
